package com.ruoyi.product.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.product.domain.ProductWelderDispatch;
import com.ruoyi.product.service.IProductWelderDispatchService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 二次派工Controller
 * 
 * @author ruoyi
 * @date 2023-02-11
 */
@Controller
@RequestMapping("/product/dispatch")
public class ProductWelderDispatchController extends BaseController
{
    private String prefix = "product/dispatch";

    @Autowired
    private IProductWelderDispatchService productWelderDispatchService;

    @RequiresPermissions("product:dispatch:view")
    @GetMapping()
    public String dispatch()
    {
        return prefix + "/dispatch";
    }

    /**
     * 查询二次派工列表
     */
    @RequiresPermissions("product:dispatch:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ProductWelderDispatch productWelderDispatch)
    {
        startPage();
        List<ProductWelderDispatch> list = productWelderDispatchService.selectProductWelderDispatchList(productWelderDispatch);
        return getDataTable(list);
    }

    /**
     * 导出二次派工列表
     */
    @RequiresPermissions("product:dispatch:export")
    @Log(title = "二次派工", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ProductWelderDispatch productWelderDispatch)
    {
        List<ProductWelderDispatch> list = productWelderDispatchService.selectProductWelderDispatchList(productWelderDispatch);
        ExcelUtil<ProductWelderDispatch> util = new ExcelUtil<ProductWelderDispatch>(ProductWelderDispatch.class);
        return util.exportExcel(list, "二次派工数据");
    }

    /**
     * 新增二次派工
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存二次派工
     */
    @RequiresPermissions("product:dispatch:add")
    @Log(title = "二次派工", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ProductWelderDispatch productWelderDispatch)
    {
        return toAjax(productWelderDispatchService.insertProductWelderDispatch(productWelderDispatch));
    }

    /**
     * 修改二次派工
     */
    @RequiresPermissions("product:dispatch:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        ProductWelderDispatch productWelderDispatch = productWelderDispatchService.selectProductWelderDispatchById(id);
        mmap.put("productWelderDispatch", productWelderDispatch);
        return prefix + "/edit";
    }

    /**
     * 修改保存二次派工
     */
    @RequiresPermissions("product:dispatch:edit")
    @Log(title = "二次派工", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ProductWelderDispatch productWelderDispatch)
    {
        return toAjax(productWelderDispatchService.updateProductWelderDispatch(productWelderDispatch));
    }

    /**
     * 删除二次派工
     */
    @RequiresPermissions("product:dispatch:remove")
    @Log(title = "二次派工", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(productWelderDispatchService.deleteProductWelderDispatchByIds(ids));
    }
}
